'use strict'
export function Grid (x = 40, y = 10, x2 = 15, y2 = 30) {
  return { x: x, y: y, x2: x2, y2: y2 }
}
/**
 * X 轴
 * @param data { Array } ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日']
 * @param boundaryGap { Boolean } [true] 柱子是否和坐标轴有边框间隔
 */
export function XAxis (data = [], boundaryGap = true) {
  return {
    type: 'category',
    data: data,
    axisLine: {
      show: false,
      lineStyle: {
        color: 'white'
      }
    },
    offset: 2,
    axisTick: {
      show: false,
      alignWithLabel: true,
      lineStyle: {
        color: '#FFF'
      }
    },
    boundaryGap: boundaryGap,
    splitLine: {
      show: false,
      lineStyle: {
        color: ['#243753'],
        type: 'solid'
      }
    },
    axisLabel: {
      show: true,
      fontSize: 10,
      color: '#7BCAFF'
    }
  }
}

/**
 * Y 轴
 * @param config { Object }
 */
export function YAxis (unit = null) {
  return {
    minInterval: 1,
    type: 'value',
    name: unit,
    min: 0,
    nameTextStyle: {
      color: '#C1C1C1',
      fontSize: 8,
      nameLocation: 'end',
      padding: [1, 25, 0, 0]
    },
    axisLine: {
      show: true,
      lineStyle: {
        color: '#243753'
      }
    },
    splitLine: {
      show: true,
      lineStyle: {
        color: ['#243753'],
        type: 'dashed'
      }
    },
    axisTick: {
      show: false
    },
    axisLabel: {
      show: true,
      fontSize: 10,
      color: '#FFF'
    },
    boundaryGap: ['20%', '20%']
  }
}

export function Tooltip (unit = null) {
  return {
    // item || shadow
    trigger: 'axis',
    axisPointer: {
      type: 'shadow'
    },
    formatter: function (params) {
      let str = ''
      str = `${params[0].name} : ${params[0].data} `
      return str
    }
  }
}

/**
 * 数据部分
 * @param series { Array } [ 10, 20, 30, 40, 50, 60, 70]
 */
export function Series (series = []) {
  const max = Math.max.apply(null, series)
  return [
    {
      type: 'pictorialBar',
      itemStyle: { color: '#E60030' },
      symbolRepeat: 'fixed',
      symbolMargin: 2,
      symbol: 'rect',
      symbolClip: true,
      symbolSize: [8, 5],
      symbolPosition: 'start',
      symbolOffset: [0, 0],
      data: series,
      z: 2,
      animationEasing: 'elasticOut'
    },
    {
      type: 'pictorialBar',
      itemStyle: { color: '#00257E' },
      symbolRepeat: 'fixed',
      symbolMargin: 2,
      symbol: 'rect',
      symbolClip: true,
      symbolSize: [8, 5],
      symbolPosition: 'start',
      symbolOffset: [0, 0],
      data: series.map(i => max + 10),
      z: 1,
      animationEasing: 'elasticOut'
    }
  ]
}
